While not technically incorrect, the omission of curly braces can be misleading and may lead to the introduction of errors during maintenance.
In the following example, the two calls seem to be attached to the if
statement, but only the first one is, and
checkSomething
will always be executed:
if (condition) // Noncompliant
executeSomething();
checkSomething();
Adding curly braces improves the code readability and its robustness:
if (condition) {
executeSomething();
checkSomething();
}
The rule raises an issue when a control structure has no curly braces.